<?php
namespace app\models;

use yii;
use yii\db\Query;

class CustomerUpdateLog
{
    private $table;

    public function __construct()
    {
        $this->table = yii::$app->db->tablePrefix.'customer_update_log';
    }

    public function insert($data)
    {
        return yii::$app->db->createCommand()->insert($this->table,$data)->execute();
    }

    /**
     * in查询所有记录
     * @param array $arr
     * @return array
     */
    public function list($arr=[]) 
    {
        $db = new Query();
        return $db->select('*')->from($this->table)->where(['in','customer_id',$arr])->andWhere(['status'=>1])->all();
    }

    /**
     * list
     */
    public function list_all()
    {
        $db = new Query();
        $list = $db->select('*')->from($this->table)->orderBy(['id'=>SORT_DESC])->all();
        return $list;
    }

    /**通过参数获取list
     * @param $data
     * @return array
     */
    public function getListByParam($data)
    {
        $db = new Query();
        return $db->select('*')->from($this->table)->where($data)->all();
    }

    /**通过id获取一条记录
     * @param $id
     * @return bool|mixed
     */
    public function getRecordById($id)
    {
        if (!$id) {
            return false;
        }
        $db = new Query();
        $info = $db->select('*')->from($this->table)->where(['id'=>$id])->limit(1)->one();
        return $info;
    }

    public function updateStatus($id)
    {
        yii::$app->db->createCommand()->update($this->table,['status'=>2],['customer_id'=>$id])->execute();
    }
}